#pragma once

class Interface_SplashScreen_Effect_Cloud
{
	class Cloud_Action : public Graphic_Particle_PolicyTemplate
	{
	public:
		inline virtual void operator()(Graphic_Particle & Target)
		{
			if(Target.mLife < -1.0f) 
			{
				Target.mRespawn = true;
				return;
			}
			if(Target.mLife > 255.0f || Target.mLife < 0.0f)
			{
				if(Target.mScaleDelta.x == 0)
				{
					Target.mScaleDelta.x = 1.0f;
					Target.mLifeDelta = -Target.mLifeDelta;	
				}
			}
			if(Target.mPosition.x - Target.mBearing > APP_WIDTH * 0.6f)
			{
				Target.mRespawn = true;
				return;
			}
			Target.mPosition += Target.mVelocity * mfInterval;
			Target.mLife += Target.mLifeDelta * mfInterval;
			Target.mColor = ARGB((Target.mLife > 255)? 255 : (Target.mLife < 0)? 0 : Target.mLife, 255, 255, 255);
		}
	};

	class Cloud_Initialize : public Graphic_Particle_PolicyTemplate
	{
	public:
		inline virtual void operator()(Graphic_Particle & Target)
		{
			Target.mVelocity.x = System_Utility::RandomFloat(20.0f, 60.0f);
			Target.mVelocity.y = System_Utility::RandomFloat(-5.0f, 5.0f);
			float size = System_Utility::RandomFloat(4.0f, 7.5f) * 0.1f;
			Target.mScale = Vector2(size, size);
			Target.mScaleDelta.y = (rand() % 4) * 1.0f;
			Target.mScaleDelta.x = 0;
			Target.mBearing = 256.0f * size * 0.5f;
			if(Target.mPosition.x + Target.mBearing > -APP_WIDTH * 0.6f)
			{
				Target.mLife = 0.0f;
				Target.mLifeDelta = System_Utility::RandomFloat(10.0f, 40.0f);
			}
			else
			{
				Target.mPosition.x -= Target.mBearing;
				Target.mLife = System_Utility::RandomFloat(1.0f, 255.0f);
				if(Target.mLife < 150)
					Target.mLifeDelta = System_Utility::RandomFloat(10.0f, 20.0f);
				else
					Target.mLifeDelta = -System_Utility::RandomFloat(10.0f, 20.0f);
			}
		}
	};
	typedef Graphic_ParticleSystem <Cloud_Initialize, Cloud_Action> ParticleSystem;
	SmartPtr	<ParticleSystem>	mHandler;
	SmartPtr	<hgeSprite>			mCloudImg;
	std::deque	<Vector2>			mSpawnPoints;

	float		mTimepassed;
public:
	Interface_SplashScreen_Effect_Cloud();
	~Interface_SplashScreen_Effect_Cloud();

	bool Initialize();

	void Update(const float & Interval);
	void Render();
};